<?php

/**
 * CodeRS - Atviras kodas Lietuvai
 * Copyright (C) 2007 CodeRS www.coders.lt info@coders.lt
 * MightMedia TVS
 * shoutbox.php - Rėksnių dėžutė
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 * 
 * Ši programa yra laisva. Jūs galite ją platinti ir/arba modifikuoti
 * remdamiesi Free Softw	$cache->remove("block", "shoutbox_s");
	$cache->remove("block", "shoutbox_p");are Foundation paskelbtomis GNU Bendrosios
 * Viešosios licencijos sąlygomis: 2 licencijos versija, arba (savo
 * nuožiūra) bet kuria vėlesne versija.
 * 
 * Ši programa platinama su viltimi, kad ji bus naudinga, bet BE JOKIOS
 * GARANTIJOS; be jokios numanomos PERKAMUMO ar TINKAMUMO KONKRETIEMS
 * TIKSLAMS garantijos. Žiūrėkite GNU Bendrąją Viešąją licenciją norėdami
 * sužinoti smulkmenas.
 * 
 * Jūs turėjote kartu su šia programa gauti ir GNU Bendrosios Viešosios
 * licencijos kopija; jei ne - rašykite Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**/

if (!defined("OK")) { header("HTTP/1.0 404 Not Found"); }

if (isset($_POST['chat_box']) && $_POST['chat_box'] == 'Siųsti' && !empty($_POST['chat_msg']) && PRISIJUNGES) {
	$db->uzklausa("INSERT INTO `".T_SAUKYKLA."` SET `nikas`='".$db->fix($ses->user_data['username'])."', `msg`='".$db->fix(input($_POST['chat_msg']))."', `time`='".time()."', `niko_id`='".(int) $ses->user_data['user_id']."'");
	unset($_POST['chat_msg'], $_POST['chat_box']);
	$cache->remove("block", "shoutbox_s");
	$cache->remove("block", "shoutbox_p");
}

// Koki cache faila priskirti?
if(PRISIJUNGES) $shoutbox = "shoutbox_p";
else $shoutbox = "shoutbox_s";

$result = $cache->get('block', $shoutbox);
if ($result != false) {
	echo $result;
} else {
	ob_start();

	echo "<script type=\"text/javascript\">
function nick(tekstas){
	if (document.chatbox.chat_msg.value == \"\") {
	document.chatbox.chat_msg.value=tekstas;
	} else {
	document.chatbox.chat_msg.value+=\" \"+ tekstas;
	document.chatbox.chat_msg.focus();
	}
}
</script>";
	if (PRISIJUNGES) {
		$chat_box = '<form name="chatbox" action="" method="post">
		<textarea name="chat_msg" style="width:95%;height:60px;"></textarea><br />
		<input type="submit" name="chat_box" value="Siųsti" />
		</form>';
	} else {
		$chat_box = '<textarea style="width:95%;height:40px;" disabled="disabled">Turite prisijungti.</textarea><br /><input type="submit" value="Siųsti" disabled="disabled" />';
	}
	$chat_box .= "<hr />";
	$chat = $db->uzklausa("SELECT * FROM `".T_SAUKYKLA."` ORDER BY `time` DESC LIMIT ".$conf['Chat_limit']."");
	while($row = $db->masyvas($chat)) {
		$extra = "";
		if (PRISIJUNGES && $row['nikas'] != $ses->user_data['username']) $extra .= '<a href="?id,47;m,'.$row['niko_id'].'"><img src="images/icons/user.png"></a><a href="?id,45;n,1;u,'.$row['nikas'].'"><img src="templates/default/images/pm/mail.png" alt="pm" /></a> ';
		//if (ADMIN) $extra .= "<a href='?id,49;d,".$row['id']."' onclick=\"return confirm('Ar tikrai norite trinti?')\"><img src='images/icons/page_white_delete.png' alt='[d]' title='trinti' class='middle' border='0' /></a> <a href='?id,49;r,".$row['id']."'><img src='images/icons/page_white_edit.png' alt='[r]' title='redaguoti' class='middle' border='0' /></a> <a href='?id,49;b,".$row['niko_id']."'  onclick=\"return confirm('Ar tikrai norite blokuoti?')\"><img src='images/icons/user_delete.png' alt='[b]' title='baninti' class='middle' border='0' /></a>";
		//create_date($format, time(), $tz)
		$chat_box .= "<div class=\"sarasas\"><a onclick=\"nick('[b]".$row['nikas']."[/b], ')\" title=\"header=[".$row['nikas']."] body=[<br/>Data: <b>".$row['time']."</b><br/>Kada: <b>".kada($row['time'])."</b><br/><br/>] cssbody=[sarasas] cssheader=[title] fade=[on]\"><b>".$row['nikas']."</b></a> ".$extra."<br />".smile(bbchat(wrap($row['msg'],25)))."</div>";
	}
	$chat_box .= "<a href=\"?id,49\" title=\"Archyvas\">Archyvas</a>";

	echo style_block("Šaukykla", $chat_box);

	$result = ob_get_contents();
	ob_end_clean();

	$cache->set('block', $shoutbox, $result, (time() + (60*60*24) ));// Po 24 h privalomas cache atnaujinimas
	echo $result;
}
unset($result);
?>
